//
//  EnduranceVC.m
//  TT
//
//  Created by Lenny on 16/4/21.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "EnduranceVC.h"

//views
#import "EnduranceCell.h"

@interface EnduranceVC ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    CGFloat _topHigh,_cellHigh;
    NSString *_endCell;
}
@property(nonatomic,strong)UIView *topV;
@property(nonatomic,strong)UICollectionView *listCV;

@end

@implementation EnduranceVC

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor yellowColor];
    [self setData];
    [self UI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - delegate motheds

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    EnduranceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_endCell forIndexPath:indexPath];
    [cell addEvent:^(UIButton *btn) {
       
        NSLog(@"fsfsfsfs");
    }];
    return cell;
}

#pragma mark - private motheds

- (void)setData {
    
    _topHigh = 200;
    _cellHigh = 80;
    _endCell = @"enduranceCell";
}

- (void)UI {
    
    [self.view addSubview:self.topV];
    [self.view addSubview:self.listCV];
    
    __weak typeof(self) weakSelf = self;
    [self.topV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(_topHigh);
    }];
    
    [self.listCV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(weakSelf.topV.mas_bottom);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-k_M_Tabbar_h);
    }];

}

#pragma mark - setters and getters

- (UIView *)topV {
    
    if (_topV == nil) {
        
        _topV = [[UIView alloc] init];
        _topV.backgroundColor = [UIColor blueColor];
    }
    return _topV;
}

- (UICollectionView *)listCV {
    
    if (_listCV == nil) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(k_screen_w, _cellHigh);
        flowLayout.minimumInteritemSpacing = 5;
        flowLayout.minimumLineSpacing = 5;
        _listCV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _listCV.dataSource = self;
        _listCV.delegate = self;
        [_listCV registerClass:[EnduranceCell class] forCellWithReuseIdentifier:_endCell];
        _listCV.contentInset = UIEdgeInsetsMake(5, 0, 5, 0);
        _listCV.backgroundColor = WL_Back_Gray_Color;
    }
    return _listCV;
}


@end
